package com.xinou.daily_report.controller;

import com.xinou.common.base.config.ApiResponse;
import com.xinou.daily_report.PO.okForm.*;
import com.xinou.daily_report.VO.OkFormCountVO;
import com.xinou.daily_report.VO.OkFormInfoVO;
import com.xinou.daily_report.service.SysOkFormService;
import com.xinou.daily_report.utils.ConstUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lcc
 * @create 2021-07-05
 * @注意 本内容仅限于xinou内部传阅，禁止外泄以及用于其他的商业目的
 */
@RestController
@RequestMapping("/mini/okForm")
@Api(tags = {"前台 ok单"})
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MiniOkFormController {
    final SysOkFormService sysOkFormService;

    @PostMapping("save")
    @ApiOperation("添加ok单")
    @RequiresPermissions({"mini:okForm:save"})
    public ApiResponse<String> okFormSave(@RequestBody OkFormAddPO po){
        return sysOkFormService.okFormSave(po);
    }

    @PostMapping("list")
    @ApiOperation("获取ok单列表")
    @RequiresPermissions({"mini:okForm:list"})
    public ApiResponse<OkFormInfoVO> okFormList(@RequestBody OkFormListPO po){
        po.setIsMini(1);
        return sysOkFormService.okFormList(po);
    }

    @PostMapping("count")
    @ApiOperation("获取ok单统计")
//    @RequiresPermissions({"mini:okForm:count"})
    public ApiResponse<OkFormCountVO> okFormCount(){
        return sysOkFormService.okFormCount();
    }

    @PostMapping("update")
    @ApiOperation("修改ok单")
    @RequiresPermissions({"mini:okForm:update"})
    public ApiResponse<String> okFormUpdate(@RequestBody OkFormUpdatePO po){
        return sysOkFormService.okFormUpdate(po);
    }

    @PostMapping("delete")
    @ApiOperation("删除ok单")
    @RequiresPermissions({"mini:okForm:delete"})
    public ApiResponse<String> okFormDelete(@RequestBody OkFormDeletePO po){
        return sysOkFormService.okFormDelete(po);
    }

    @PostMapping("complete")
    @ApiOperation("完成")
    @RequiresPermissions({"mini:okForm:complete"})
    public ApiResponse<Void> okFormComplete(@RequestBody OkFormStatusPO po){
        po.setStatus(ConstUtil.OK_FORM_FINISHED);
        return sysOkFormService.okFormStatus(po);
    }

    @PostMapping("confirm")
    @ApiOperation("确认")
    @RequiresPermissions({"mini:okForm:confirm"})
    public ApiResponse<Void> okFormConfirm(@RequestBody OkFormStatusPO po){
        po.setStatus(ConstUtil.OK_FORM_CONFIRMED);
        return sysOkFormService.okFormStatus(po);
    }

}
